﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace IceDog.Uop.Models.Migrations
{
    public partial class initial : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "uop_product",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Guid = table.Column<string>(nullable: true),
                    Code = table.Column<string>(nullable: true),
                    Name = table.Column<string>(nullable: true),
                    JoinDate = table.Column<DateTime>(nullable: false),
                    UnitPricePerKg = table.Column<decimal>(nullable: false),
                    FromAddress = table.Column<string>(nullable: true),
                    Remark = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_uop_product", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "uop_user",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Guid = table.Column<string>(nullable: true),
                    Name = table.Column<string>(nullable: true),
                    Gender = table.Column<int>(nullable: false),
                    Age = table.Column<ushort>(nullable: false),
                    Address = table.Column<string>(nullable: true),
                    MobilePhone = table.Column<string>(nullable: true),
                    Birthday = table.Column<DateTime>(nullable: false),
                    IsDeleted = table.Column<bool>(nullable: false),
                    Remark = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_uop_user", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "uop_order",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Guid = table.Column<string>(nullable: true),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    EndTime = table.Column<DateTime>(nullable: false),
                    UserId = table.Column<int>(nullable: false),
                    Remark = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_uop_order", x => x.Id);
                    table.ForeignKey(
                        name: "FK_uop_order_uop_user_UserId",
                        column: x => x.UserId,
                        principalTable: "uop_user",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "uop_order_detail",
                columns: table => new
                {
                    OrderId = table.Column<int>(nullable: false),
                    ProductId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_uop_order_detail", x => new { x.OrderId, x.ProductId });
                    table.ForeignKey(
                        name: "FK_uop_order_detail_uop_order_OrderId",
                        column: x => x.OrderId,
                        principalTable: "uop_order",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_uop_order_detail_uop_product_ProductId",
                        column: x => x.ProductId,
                        principalTable: "uop_product",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_uop_order_UserId",
                table: "uop_order",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_uop_order_detail_ProductId",
                table: "uop_order_detail",
                column: "ProductId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "uop_order_detail");

            migrationBuilder.DropTable(
                name: "uop_order");

            migrationBuilder.DropTable(
                name: "uop_product");

            migrationBuilder.DropTable(
                name: "uop_user");
        }
    }
}
